import {
	IsString,
	Matches,
	IsJSON,
	IsEnum,
	IsEmail,
	IsNotEmpty,
	IsPhoneNumber,
	Min,
	Length,
	IsOptional,
	IsBoolean,
	IsNumber,
} from 'class-validator'
// import { ApiProperty } from '@nestjs/swagger'
import { compareSync } from 'bcryptjs'
import { ErrorEnum } from '@/constants/error-code.constant'

export enum StatusEnum {
	STATIC = '0',
	DYNAMIC = '1',
}

export class LoginDto {
	// @ApiProperty({ description: '用户名' })
	@IsString()
	@Length(4, 10, { message: ErrorEnum.INVALID_USERNAME_PASSWORD })
	username: string

	// @ApiProperty({ description: '密码', example: 'a123456' })
	@IsString()
	// @Matches(/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Za-z])\S*$/, { message: ErrorEnum.INVALID_USERNAME_PASSWORD })
	// @Length(6, 20, { message: ErrorEnum.INVALID_USERNAME_PASSWORD })
	password: string

	// @ApiProperty({ description: '验证码标识' })
	@IsOptional()
	@IsString()
	captchaKey: string

	// @ApiProperty({ description: '验证码' })
	@IsOptional() // 可选装饰器
	@IsString()
	code: string

	// @BeforeInsert()
	// async encryptPwd() {
	// 	this.password = await bcrypt.hashSync(this.password)
	// }
}

export class RegisterDto extends LoginDto {}

export class ClientInfoDto {
	ip: string
	ua: string
	browser: string
	os: string
	loginLocation: string
}
